//
//  TFAudioPlayer.m
//  Recorder
//
//  Created by chenTengfei on 15/2/1.
//  Copyright (c) 2015年 chenTengfei. All rights reserved.
//

#import "TFAudioPlayer.h"

@implementation TFAudioPlayer

#pragma mark - 公共方法

- (BOOL)play
{
    // 后台设置
    [self setAudioSession];
    if ([self isPlaying]) {
        [self stop];
    }

    return [super play];
}

+ (TFAudioPlayer *)playWithMP3SavePath:(NSString *)pathStr
{
    NSError *error;
    
    // 创建新的播放器
    TFAudioPlayer *newTFAudioPlayer = [[TFAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:pathStr] error:&error];
    if (error != nil) {
        NSLog(@"----创建播放器错误!");
        return nil;
    } else {
        newTFAudioPlayer->_pathStr = pathStr;
//        [newTFAudioPlayer play];
        return newTFAudioPlayer;
    }
}

#pragma mark - 私有方法
/**
 *  设置音频会话
 */
- (void)setAudioSession {
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    [[AVAudioSession sharedInstance] setActive:YES error:nil];
}

@end
